//
//  UserAddressController.m
//  PersonnelWashCar
//
//  Created by 张越 on 16/4/22.
//  Copyright © 2016年 张越. All rights reserved.
//

#import "UserAddressController.h"

@interface UserAddressController ()
@property (strong, nonatomic) IBOutlet UITextField *addressTextField;

@end

@implementation UserAddressController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"家庭住址";
    __weak typeof(self)weakSelf = self;
    [self addLeftButtonWithImage:[UIImage imageNamed:@"返回箭头"] actionBlock:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    [self addRightButtonWithTitle:@"完成" actionBlock:^{
        if ([weakSelf.addressTextField.text isEqual:@""]) {
            [SVProgressHUD showErrorWithStatus:@"请输入家庭住址"];
        } else {
            [weakSelf web_requestChangeAddress];
        }
    }];
    
}

- (void)web_requestChangeAddress
{
    NSString *uidStr = [[NSUserDefaults standardUserDefaults] objectForKey:KUserDefaultsUserIdKey];
    NSDictionary *dict =  @{@"uid" : uidStr,@"param" : @"address",@"value" : self.addressTextField.text};
    __weak typeof(self)weakSelf = self;
    [HttpRequestManager getMethod:KChangeUserInfoInterface parameters:dict completedMainBlock:^(BOOL success, id response, NSString *errMsg) {
        if (success) {
            [[NSUserDefaults standardUserDefaults] setObject:self.addressTextField.text forKey:KUserDefaultAddress];
            [[NSUserDefaults standardUserDefaults] synchronize];
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else{
            [SVProgressHUD showErrorWithStatus:@"失败"];
        }
    }];
}

- (void)viewDidAppear:(BOOL)animated
{
    [self.addressTextField becomeFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
